<?php

/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/15
 * Time: 12:51
 */

namespace App\Http\Controllers\h5;

use App\Http\Controllers\BaseController;
use App\Models\LogModel;
use App\Services\OrdersPayService;
use App\Models\MoneyBilModel;
use DB;
use App\Sdk\Pay\Alipay;
use Illuminate\Http\Request;
use App\admin\Service\OA;
use App\Jobs\Fun;
class MoneyController extends BaseController {

    protected $orderPayService;

    public function __construct(OrdersPayService $orderPayService) {
        parent::__construct();
        $this->orderPayService = $orderPayService;
    }

    public function index() {
         $user = OA::$user->getModel();
        if (!$user) {
            return  Fun::goLogin();
        } 
        return view('h5.money.index');
    }

    public function chongzhi() {
          $user = OA::$user->getModel();
        if (!$user) {
            return  Fun::goLogin();
        } 
        return view('h5.money.chongzhi');
    }
    
    public function tixian(){
          $user = OA::$user->getModel();
        if (!$user) {
            return  Fun::goLogin();
        } 
         return view('h5.money.tixian');
    }
    public function tixianinfo(){
          $user = OA::$user->getModel();
        if (!$user) {
            return  Fun::goLogin();
        } 
         return view('h5.money.tixianinfo');
    }
    public function jilu(){
          $user = OA::$user->getModel();
        if (!$user) {
            return  Fun::goLogin();
        } 
         return view('h5.money.jilu');
    }
    
    /**
     * 订单详细记录
    */
    public function info(){
          $user = OA::$user->getModel();
        if (!$user) {
            return  Fun::goLogin();
        } 
         return view('h5.money.info');
    }
    
   
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     * 支付宝统一支付结果回调处理
     * @param Request $request
     * @return string

    private function notify_del(Request $request) {


        info('pay:alipay:parmer:' . json_encode($_POST));
        info('pay:GET:' . json_encode($_GET));
        LogModel::add('pay:alipay:parmer:' . json_encode($_POST));
        LogModel::add('pay:GET:' . json_encode($_GET));
        try {
            //参数处理
            $channel = trim($request->input('channel', 'm'));
            $type = intval($request->input('type', 1));
            if (!$channel || !$type) {
                info('pay:支付失败，参数不全');

                LogModel::add('pay:支付失败，参数不全', LogModel::typeError);
                return 'fail';
            }

            $tradeData = array_merge($_POST, $_GET);
            //调用方法
            $result = $this->orderPayService->alipayReceiveOrder($channel, $tradeData);
            if ($result) {
                $status = $this->chongzhisuccess($tradeData); 
                LogModel::add("支付回调调用状态:" . $status);
                if ($status) {
                    $status = 'success';
                } else {
                    LogModel::add("支付回调调用事务失败:" . $this->error, LogModel::typeError);
                    LogModel::add("支付回调调用失败:" . $this->orderPayService->error, LogModel::typeError);
                }
                return $status;
            }
        } catch (\Exception $e) {
            LogModel::add('pay:alipay:' . $e->getMessage(), LogModel::typeError);
            info('pay:alipay:' . $e->getMessage());
        }
        return 'fail';
    }
         */





    public function success() {
      return view('h5.money.success');
    }

}
